package com.demon.framework.common.retcode;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

/**
 * 系统错误码,其他业务模块继承该类
 */
@Getter
@ToString
public class BaseRetCode {

    /**
     * 操作成功
     */
    public static final RetCode OK;
    /**
     * 操作失败
     */
    public static final RetCode ERR_FAILED;
    /**
     * 系统繁忙，请稍后重试
     */
    public static final RetCode ERR_SERVER_EXCEPTION;
    /**
     * 参数错误
     */
    public static final RetCode ERR_BAD_PARAMS;
    /**
     * 参数错误
     */
    public static final RetCode ERR_ARG_TYPE_MISMATCH;
    /**
     * 无访问权限
     */
    public static final RetCode ERR_FORBIDDEN;
    /**
     * 非法JSON串
     */
    public static final RetCode ERR_INVALID_JSON;
    /**
     * 资源不存在
     */
    public static final RetCode ERR_NOT_FOUND;
    /**
     * 不支持该操作
     */
    public static final RetCode ERR_OPERATION_NOT_SUPPORTED;

    /**
     * JWT Token 格式错误
     */
    public static final RetCode TOKEN_EXPIRED;

    static {
        OK = RetCode.newInstance("操作成功", "OK");

        ERR_FAILED = RetCode.newInstance("操作失败", "ERR_FAILED");
        ERR_SERVER_EXCEPTION = RetCode.newInstance("系统繁忙，请稍后重试", "ERR_SERVER_EXCEPTION");
        ERR_BAD_PARAMS = RetCode.newInstance("参数错误", "ERR_BAD_PARAMS");
        ERR_ARG_TYPE_MISMATCH = RetCode.newInstance("参数类型错误", "ERR_ARG_TYPE_MISMATCH");
        ERR_FORBIDDEN = RetCode.newInstance("无访问权限", "ERR_FORBIDDEN");
        ERR_INVALID_JSON = RetCode.newInstance("非法JSON串", "ERR_INVALID_JSON");
        ERR_NOT_FOUND = RetCode.newInstance("资源不存在", "ERR_NOT_FOUND");
        ERR_OPERATION_NOT_SUPPORTED = RetCode.newInstance("不支持该操作", "ERR_OPERATION_NOT_SUPPORTED");

        // 登录鉴权
        TOKEN_EXPIRED = RetCode.newInstance("登录失效，请重新登录", "TOKEN_EXPIRED");
    }


    /**
     * 错误码
     */
    @Getter
    @ToString
    @AllArgsConstructor
    public final static class RetCode {

        public String message;
        public String code;

        public static final RetCode newInstance(String message, String code) {
            return new RetCode(message, code);
        }
    }

}
